package com.ym521.activitystack.core.foreground

import android.app.Activity
import android.app.Application
import android.os.Bundle
import androidx.fragment.app.FragmentActivity

/**
 *@author Ym
 *E-mail: 2435970206@qq.com
 *createTime:2024/3/31
 *explain:
 *
 */
internal abstract class ActivityLifecycleCallback: Application.ActivityLifecycleCallbacks {
    @Volatile
    protected var activitySum = 0

    abstract fun onActivityCreated(activity: FragmentActivity)

    abstract fun onActivityDestroyed(activity: FragmentActivity)

    override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
        if (activity is FragmentActivity)
            onActivityCreated(activity)
    }

    override fun onActivityStarted(activity: Activity) {
        this.activitySum++
    }

    override fun onActivityResumed(activity: Activity) {}

    override fun onActivityPaused(activity: Activity) {}

    override fun onActivityStopped(activity: Activity) {
        this.activitySum--
    }

    override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {}

    override fun onActivityDestroyed(activity: Activity) {
        if (activity is FragmentActivity)
            onActivityDestroyed(activity)
    }


}